//
//  NSString+SDPinyin.m
//  SuperDoctor
//
//  Created by 李忠 on 7/11/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "NSString+SDPinyin.h"

@implementation NSString (SDPinyin)

- (NSString *)sd_transformToPinyin{
    
    NSMutableString *mutableString = [NSMutableString stringWithString:self];
    CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformToLatin, false);
    mutableString = (NSMutableString *)[mutableString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:[NSLocale currentLocale]];
    mutableString = [[mutableString stringByReplacingOccurrencesOfString:@" " withString:@""] mutableCopy];
    
    return mutableString.lowercaseString;
}

- (NSString *)sd_transformToPinyinFirstLetter{
    
    NSMutableString *stringM = [NSMutableString string];
    
    NSString *temp = nil;
    for (int i = 0; i < [self length]; i++) {
        temp = [self substringWithRange:NSMakeRange(i, 1)];
        
        NSMutableString *mutableString = [NSMutableString stringWithString:temp];
        CFStringTransform((CFMutableStringRef)mutableString, NULL, kCFStringTransformToLatin, false);
        mutableString = (NSMutableString *)[mutableString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:[NSLocale currentLocale]];
        mutableString = [[mutableString substringToIndex:1] mutableCopy];
        
        
        [stringM appendString:(NSString *)mutableString];
        
    }
    
    return stringM.lowercaseString;
}














































@end
